<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>微博找事</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/font-awesome.min93e3.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/iCheck/custom.css"/>
<style type="text/css">
body{padding:10px;font-size: 14px;}
.searchCondition>div>a{margin-right: 20px;color: black;}
.searchCondition>div>a.cfoucs{color: #1ab394;font-weight: bold;}
.radio-primary input[type="radio"] + label::after {background-color: #1ab394;}
.radio-primary input[type="radio"]:checked + label::after {background-color: #1ab394;}
.radio-primary input[type="radio"]:checked + label::before {border-color: #1ab394;}
table>tbody>tr:first-child>td:first-child{width: 20px;vertical-align: top;}
table>tbody>tr:first-child>td:nth-child(2){width: 80px;vertical-align: top;}
table>tbody>tr:first-child>td:nth-child(3){border-top: 1px solid #eee;}
table>tbody>tr:nth-child(3)>td:last-child{width: 60px;text-align: right;}
table:first-child>tbody>tr:first-child>td:nth-child(3){border-top: 0;}
.icheckbox_square-green{width: 18px;height: 18px;}
.hand{cursor: pointer;}
</style>
</head>
<body class="gray-bg">
<div class="container-fluid">
	<div class="row">
		<div class="col-sm-1">
			<a href="<%=path%>/view/member/findThing/rule" style="color: #1ab394;">返回</a>
		</div>
	</div>
	<div id="starttimeOption" class="row searchCondition" style="margin-bottom:10px;background-color: white;height: 60px;line-height: 60px;">
		<div class="col-sm-5">
			<span style="color: #bbb">最近微博发布时间：</span><a class="cfoucs" starttime="">全部</a>
			<a starttime="1">近1天</a><a starttime="3">近3天</a><a starttime="7">近7天</a><a starttime="0">自定义</a>
		</div>
		<div class="col-sm-3" style="padding: 0;margin-top: 15px;" id="data_5">
			<div class="input-daterange input-group" id="datepicker">
	            <input type="text" class="input-sm form-control" name="start" value="2014-11-11" id="starttime">
	            <span class="input-group-addon" style="height: 24px;">到</span>
	            <input type="text" class="input-sm form-control" name="end" value="2014-11-17" id="endtime">
	        </div>
		</div>
	</div>
	<div class="row" style="background-color: white;padding-bottom:20px;padding-top:10px;">
		<div class="col-sm-4">
			<div class="input-group">
	            <input id="keyword" type="text" class="form-control"> <span class="input-group-btn"> 
	            <button type="button" class="btn btn-primary" id="search">搜索</button> </span>
	        </div>
		</div>
		<div class="col-sm-1" style="padding: 0;">
			<div class="radio radio-primary">
		        <input id="a" type="radio" name="order" value="a" checked="checked">
		        <label for="a">最热排序</label>
		    </div>
		</div>
		<div class="col-sm-7">
		    <div class="radio radio-primary">
		        <input id="b" type="radio" name="order" value="b">
		        <label for="b">最新排序</label>
		    </div>
		</div>
		<div class="col-sm-10">
			<div class="i-checks">
	            <label><input id="checkedAll" type="checkbox">&nbsp;全选</label>
	        </div>
		</div>
		<div class="col-sm-2  text-right">
	        <button onclick="func_del()" class="btn btn-sm btn-white" type="button" style="border-color: #18a689;">批量删除</button>
		</div>
		
	   	<div class="col-sm-12" style="border-top: 1px solid #eee;padding-top: 8px;margin-top: 8px;" id="list">
		</div>
		<div class="col-sm-12">
			<button class="btn btn-block btn-default" id="getMore"><i class="fa fa-arrow-down"></i> 显示更多</button>
		</div>
	</div>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/artDialog/7.0.0/dialog-plus.js"></script>
<script type="text/javascript" src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
<script type="text/javascript">
var path = "<%=path%>";
var ruleId = getUrlParam("ruleId");
var start = 0;		//起始记录
var length = 10;	//每页大小
var order = "a";	//排序
var weiboIds = "";	//微博id组

$(function(){
	func_initCheckbox();
	
	$("#data_5 .input-daterange").datepicker({keyboardNavigation:!1,forceParse:!1,autoclose:!0});
	$("#starttimeOption a[starttime],:radio[name='order'],#search").click(function(){
		if($(this).attr("starttime") != undefined){
			$(this).addClass("cfoucs").siblings().removeClass("cfoucs");
		}
		init();
	});
	
	$("#getMore").click(function(){
		if($(this).hasClass("btn-primary")){
			start += length;
			func_list();
		}
	});
	
	$(document).on('ifClicked',"#checkedAll",function(e){
		if(!e.currentTarget.checked){
			$(':checkbox').iCheck('check',function(){
				weiboIds = "";
				$(".myTable2").each(function(x,y){
					var a = $(this).find(":checkbox").val();
					if(a != undefined){
						weiboIds += "," + a;
					}
				});
			});			
		}else{
			$(':checkbox').iCheck('uncheck',function(){
				weiboIds = "";
			});
		}
	});
	
	$(document).on('ifClicked',".childCheckbox",function(e){
		var a = $(this).val();
		if(!e.currentTarget.checked){
			weiboIds += "," + a;
		}else{
			var str = weiboIds;
			weiboIds = "";
			$.each(str.split(","),function(i,d){
				if(d != "" && a != d){
					weiboIds += "," + d;
				}
			});
		}
	});
	
	$(document).on("click",".chatDialog",function(){
		var wbUserId = $(this).attr("wbUserId");
		var statusId = $(this).attr("statusId");
		var chatDialog = dialog({
			id:	"chatDialog",
			fixed: true,
			padding: 0,
			width:1100,
			height:450,
			title:'客户平台管理',
			url:path+"/view/member/findPeople/chat?wbUserId="+wbUserId+"&statusId="+statusId,
			cancelDisplay: false,
			cancel: function () {
				this.remove();
			}
		});
		chatDialog.showModal();
		$("iframe[name='chatDialog']:visible").attr("scrolling","auto").css("overflow-x","hidden").css("overflow-y","auto");
	});
	
	init();
});

function init(){
	start = 0;
	$("#list").html("");
	$(':checkbox').iCheck('uncheck');
	func_list();
}

function func_initCheckbox(){
	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green"});
}

function func_list(){
	var extra_search = {};
	
	extra_search.ruleId = ruleId;
	var now = new Date();
	var starttime = $("#starttimeOption .cfoucs").attr("starttime");
	var endtime = now.Format("yyyy-MM-dd hh:mm:ss");
	if(starttime != ""){
		if(starttime == 0){
			starttime = $("#starttime").val()+" 00:00:00";
			endtime = $("#endtime").val()+" 23:59:59";
		}else{
			starttime = new Date(now.getTime()-starttime*24*60*60*1000).Format("yyyy-MM-dd hh:mm:ss");
		}
		extra_search.starttime = starttime;
		extra_search.endtime = endtime;
	}
	
	var keyword = $("#keyword").val();
	if($.trim(keyword) != ""){
		extra_search.keyword = keyword;
	}
	order = $(":radio[name='order']:checked").val();
	
	var param = {draw:1,start:start,length:length,order:order,extra_search:extra_search};
	param = JSON.stringify(param);
	
	$.ajax({
		contentType:"application/json;charset=utf-8",
		type:"POST",
		dataType:"json",
		url: path+"/scan/findThing/getPage",
		data: param,
		success: function(data){
			if(data.data==null && data.data.length==0){
				return ;
			}
			
			if(data.recordsTotal>(start+length)){
				$("#getMore").removeClass("btn-default").addClass("btn-primary");
			}else{
				$("#getMore").removeClass("btn-primary").addClass("btn-default");
			}
			
			$.each(data.data,function(i,a){
				var html = "";
				html += '<table class="myTable2" style="width: 100%;">';
				html += '<tbody>';
				html += '<tr>';
				html += '<td rowspan="3"><div class="i-checks"><label><input value="'+a.id+'" class="childCheckbox" type="checkbox"></label></div></td>';
				html += '<td rowspan="3"><img src="'+a.user_profile_image_url+'"></td>';
				html += '<td colspan="2">';
				html += '<h3>'+a.user_screen_name+'</h3>';
				html += '</td>';
				html += '</tr>';
				html += '<tr>';
				html += '<td colspan="2">';
				html += '<p>'+a.status_text+'</p>';
				html += '</td>';
				html += '</tr>';
				html += '<tr>';
				html += '<td>';
				html += '<p style="font-size:12px;"><a>转发('+a.status_reposts_count+')</a>&nbsp;<a>评论('+a.status_comments_count+')</a>&nbsp;<a>赞同('+a.status_attitudes_count+')</a>&nbsp;&nbsp;<a href="http://weibo.com/'+a.user_pro'" target="_blank" style="color:#1ab394;font-size:14px;text-decoration:underline;">原文链接</a></p>';
				html += '</td>';
				html += '<td>';
				html += '<img wbUserId="'+a.user_id+'" statusId="'+a.status_id+'" src="'+path+'/images/comments_16.png" class="hand chatDialog">&nbsp;&nbsp;<img onclick="func_del('+a.id+')" src="'+path+'/images/delete_16.png" class="hand">';
				html += '</td>';
				html += '</tr>';
				html += '</tbody>';
				html += '</table>';
				
				$("#list").append(html);
			});
			
			func_initCheckbox();
		}
	});
}

function func_del(id){
	if(confirm("是否删除")){
		if(id){
			$.post(path+"/scan/findThing/delWeibo",{id:id},function(data){
				init();
			});
		}else{
			$.each(weiboIds.split(","),function(i,d){
				if(d != ""){
					$.post(path+"/scan/findThing/delWeibo",{id:d},function(data){
						init();
					});
				}
			});
		}
	}
}

function getUrlParam(key){
	var reg = new RegExp("(^|&)"+ key +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}

Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
</script>
</html>